/* GUI CONVERTED from rcsomtd.p (converter v1.76) Fri May  3 13:22:27 2002 */
/* rcsomtd.p - Release Management Customer Schedules : Line Detail Maint*/
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.7.1.5 $                                             */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.3    LAST MODIFIED: 02/02/96           BY: kjm *G1LT*    */
/* REVISION: 8.5    LAST MODIFIED: 06/07/95           BY: gwm *J0M0*    */
/* REVISION: 8.6    LAST MODIFIED: 09/20/96           BY: TSI *K005*    */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane        */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan       */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb              */
/* Old ECO marker removed, but no ECO header exists *F0PN*                  */
/* Revision: 1.7.1.3     BY: Dan Herman       DATE: 07/09/01  ECO: *P007*   */
/* Revision: 1.7.1.4     BY: Patrick Rowan    DATE: 03/08/02  ECO: *P00G*   */
/* $Revision: 1.7.1.5 $    BY: Katie Hilbert    DATE: 04/15/02  ECO: *P03J*   */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* SCHEDULED ORDER MAINT SUBPROGRAM - LINE ITEM DETAIL */

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define shared variable scx_recno    as recid.
define shared variable so_recno     as recid.
define shared variable sod_recno    as recid.
define shared variable cmtindx      like cmt_indx.
define shared variable impexp       like mfc_logical no-undo.
define shared variable impexp_label as character format "x(8)" no-undo.

define variable pkg_code_alt      like pt_part extent 7
                                  label " Alternate Container " no-undo.
define variable i                 as integer                    no-undo.
define variable ord_mult_alt      like sod_ord_mult extent 7    no-undo.
define variable charge_type_alt   like cct_charge_type extent 7 no-undo.
define variable valid_pkg_code    like sod_pkg_code             no-undo.
define variable last-field        as character                  no-undo.
define variable valid_charge_type like cct_charge_type          no-undo.
define variable v_charge_type     like cct_charge_type          no-undo.
define variable msgnbr            as integer                    no-undo.
define variable chargeable        like mfc_logical              no-undo.
define variable c-alt-container   as character format "x(20)"   no-undo.
define variable c-std-pack        as character format "x(12)"   no-undo.
define variable c-charge-type     as character format "x(12)"   no-undo.

/* VARIABLE DEFINITIONS FOR gpfile.i */
{gpfilev.i}

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
pkg_code_alt[1]
   pkg_code_alt[2]
   pkg_code_alt[3]
   pkg_code_alt[4]
   pkg_code_alt[5]
   pkg_code_alt[6]
   pkg_code_alt[7]
 SKIP(.4)  /*GUI*/
with frame alt overlay centered side-labels attr-space
    NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-alt-title AS CHARACTER.
 F-alt-title = (getFrameTitle("ALTERNATE_CONTAINERS",29)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame alt = F-alt-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame alt =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame alt + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame alt =
  FRAME alt:HEIGHT-PIXELS - RECT-FRAME:Y in frame alt - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME alt = FRAME alt:WIDTH-CHARS - .5. /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame alt:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
c-alt-container    at 8
   c-std-pack         at 28
   c-charge-type      at 42 skip(1)

   " 01."             at 3
   pkg_code_alt[1]    at 8
   ord_mult_alt[1]    at 30
   charge_type_alt[1] at 44 skip

   " 02."             at 3
   pkg_code_alt[2]    at 8
   ord_mult_alt[2]    at 30
   charge_type_alt[2] at 44 skip

   " 03."             at 3
   pkg_code_alt[3]    at 8
   ord_mult_alt[3]    at 30
   charge_type_alt[3] at 44 skip

   " 04."             at 3
   pkg_code_alt[4]    at 8
   ord_mult_alt[4]    at 30
   charge_type_alt[4] at 44 skip

   " 05."             at 3
   pkg_code_alt[5]    at 8
   ord_mult_alt[5]    at 30
   charge_type_alt[5] at 44 skip

   " 06."             at 3
   pkg_code_alt[6]    at 8
   ord_mult_alt[6]    at 30
   charge_type_alt[6] at 44 skip

   " 07."             at 3
   pkg_code_alt[7]    at 8
   ord_mult_alt[7]    at 30
   charge_type_alt[7] at 44 skip
 SKIP(.4)  /*GUI*/
with frame alt-clc overlay centered no-labels width 60
    NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-alt-clc-title AS CHARACTER.
 F-alt-clc-title = (getFrameTitle("ALTERNATE_CONTAINERS",29)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame alt-clc = F-alt-clc-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame alt-clc =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame alt-clc + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame alt-clc =
  FRAME alt-clc:HEIGHT-PIXELS - RECT-FRAME:Y in frame alt-clc - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME alt-clc = FRAME alt-clc:WIDTH-CHARS - .5. /*GUI*/


/* DETERMINE IF CONTAINER AND LINE CHARGES ARE ENABLED */
{cclc.i}

assign
   c-alt-container = getTermLabel("ALTERNATE_CONTAINER",20)
   c-std-pack      = getTermLabel("STD_PACK_QTY",12)
   c-charge-type   = getTermLabel("CHARGE_TYPE",12).

{rcordfrm.i}

find first soc_ctrl no-lock.
find first gl_ctrl no-lock.

find so_mstr where recid(so_mstr) = so_recno no-lock.
find sod_det where recid(sod_det) = sod_recno exclusive-lock.
find scx_ref where recid(scx_ref) = scx_recno no-lock.

/* DETAIL DATA ITEMS FRAME 2 */

assign
   v_charge_type     = ""
   last-field        = ""
   valid_pkg_code    = sod_pkg_code
   valid_charge_type = sod_charge_type
   sod_translt_days  = decimal(substring(so_conrep,2,6))
   sod_translt_hrs   = so_translt_hrs
   sod_psd_pat       = substring(sod_sch_data,1,2)
   sod_psd_time      = substring(sod_sch_data,3,2)
   sod_ssd_pat       = substring(sod_sch_data,5,2)
   sod_ssd_time      = substring(sod_sch_data,7,2)
   sodcmmts          = (sod_cmtindx <> 0 or
                       (new sod_det and soc_lcmmts)).

display
   sod_rbkt_days
   sod_rbkt_weeks
   sod_rbkt_mths
   sod_fab_days
   sod_raw_days
   sod_custpart
   sod_pkg_code
   sod_alt_pkg
   sod_dock
   sod_start_eff[1]
   sod_end_eff[1]
   sod_cum_qty[3]
   sod_ord_mult
   sod_psd_pat
   sod_psd_time
   sod_ssd_pat
   sod_ssd_time
   sod_conrep
   sod_cum_date[1]
   sodcmmts
   sod_charge_type
with frame sod2.

do with frame sod2 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

   ststatus = stline[3].
   status input ststatus.

   set
      sod_rbkt_days
      sod_rbkt_weeks
      sod_rbkt_mths
      sod_fab_days
      sod_raw_days
      sod_custpart    when (not so_custref_val)
      sod_pkg_code
      sod_charge_type when (using_container_charges)
      sod_alt_pkg
      sod_dock
      sod_start_eff[1]
      sod_end_eff[1]
      sod_cum_qty[3]
      sod_ord_mult
      sod_psd_pat
      sod_psd_time
      sod_ssd_pat
      sod_ssd_time
      sod_conrep
      sod_cum_date[1]
      sodcmmts
      editblk:
   editing:
      if frame-field <> "" then last-field = frame-field.
      readkey.
      apply lastkey.
      if using_container_charges then do:
         hide message.
         if (go-pending or (last-field <> frame-field))
         then do:
            if go-pending then do:
               if last-field = "sod_pkg_code" and
                  frame-field = "sod_pkg_code"
               then do:
                  if input sod_pkg_code = "" then
                     sod_charge_type = "".
                  else
                  if valid_pkg_code <> input sod_pkg_code
                  then do:
                     run validate_container
                        (input (input sod_pkg_code),
                         output chargeable,
                         output v_charge_type,
                         output msgnbr).

                     if msgnbr > 0 then do:
                        run display_msg
                           (input msgnbr,
                            input 4).
                        /* ITEM HAS NOT BEEN DEFINED AS A CONTAINER */
                        next-prompt sod_pkg_code with frame sod2.
                        next editblk.
                     end. /*IF MSGNBR > 0*/

                     if chargeable then
                        run get_charge_type
                           (input (input sod_pkg_code),
                            input (if sod_dock > "" then sod_dock else
                                   if sod_ship > "" then sod_ship else so_ship),
                            input so_curr,
                            input-output v_charge_type).
                     display v_charge_type @ sod_charge_type
                     with frame sod2.
                  end. /* ELSE IF valid_pkg_code <> */
               end. /*IF LAST-FIELD = "SOD_PKG_CODE"*/

               else
               if last-field = "sod_charge_type" and
                  frame-field = "sod_charge_type" and
                  valid_charge_type <> input sod_charge_type
                  and input sod_charge_type > ""
               then do:
                  run validate_charge_type
                     (input (input sod_charge_type),
                      input yes,
                      output msgnbr).

                  if msgnbr > 0 then do:
                     run display_msg
                        (input msgnbr,
                         input 4).
                     /* NOT A VALID CHARGE TYPE */
                     next-prompt sod_charge_type
                     with frame sod2.
                     next editblk.
                  end.
               end. /*ELSE IF last-field = "sod_charge_type" */
            end. /* IF go-pending then do*/

            else
            if last-field = "sod_pkg_code" and
               frame-field <> "sod_pkg_code" and
               input sod_pkg_code > "" and
               input sod_pkg_code <> valid_pkg_code
            then do:

               run validate_container
                  (input (input sod_pkg_code),
                   output chargeable,
                   output v_charge_type,
                   output msgnbr).

               if msgnbr > 0 then do:
                  run display_msg
                     (input msgnbr,
                      input 4).
                  /* ITEM HAS NOT BEEN DEFINED AS A CONTAINER */
                  next-prompt sod_pkg_code with frame sod2.
                  next editblk.
               end. /*IF MSGNBR > 0*/

               if chargeable then
                  run get_charge_type
                     (input (input sod_pkg_code),
                      input (if sod_dock > "" then sod_dock else
                             if sod_ship > "" then sod_ship else so_ship),
                      input so_curr,
                      input-output v_charge_type).
               display v_charge_type @ sod_charge_type
               with frame sod2.
               valid_pkg_code = input sod_pkg_code.

            end. /* ELSE IF LAST-FIELD = "SOD_PKG_CODE" */

            else
            if last-field = "sod_charge_type" and
               frame-field <> "sod_charge_type" and
               input sod_charge_type > "" and
               input sod_charge_type <> valid_charge_type
            then do:
               run validate_charge_type
                  (input (input sod_charge_type),
                   input yes,
                   output msgnbr).

               if msgnbr > 0 then do:
                  run display_msg
                     (input msgnbr,
                      input 4).
                  /* NOT A VALID CHARGE TYPE */
                  next-prompt sod_charge_type
                  with frame sod2.
                  next editblk.
               end.
               valid_charge_type = input sod_charge_type.
            end.  /* ELSE IF LAST-FIELD = "SOD_CHARGE_TYPE" */
         end. /* IF go-pending or (last-field <> frame-field))*/
      end. /*IF USING_CONTAINER_CHARGES*/
   end. /*EDITING*/

   if sod_dock > "" then do:
      find ls_mstr where ls_addr = sod_dock and ls_type = "dock"
         no-lock no-error.
      if not available ls_mstr then do:
         /* DOCK CODE DOES NOT EXIST */
         {pxmsg.i &MSGNUM=8161 &ERRORLEVEL=3}
         next-prompt sod_dock.
         undo, retry.
      end.

      find ad_mstr where ad_addr = ls_addr no-lock no-error.
      if available ad_mstr and ad_ref <> scx_shipto then do:
         /* DOCK CODE NOT FOR THIS SHIP TO */
         {pxmsg.i &MSGNUM=8162 &ERRORLEVEL=3}
         next-prompt sod_dock.
         undo, retry.
      end.
   end.

   if sod_custpart <> "" then do:
      find cp_mstr where cp_cust = so_ship
         and cp_cust_part = sod_custpart
         and cp_part = sod_part
         no-lock no-error.

      if not available cp_mstr then
      find cp_mstr where cp_cust = so_cust
         and cp_cust_part = sod_custpart
         and cp_part = sod_part
         no-lock no-error.

      if not available cp_mstr then
      find cp_mstr where cp_cust = ""
         and cp_cust_part = sod_custpart
         and cp_part = sod_part
         no-lock no-error.

      if not available cp_mstr then do:
         /* CUST/SHIP-TO ITEM NOT DEFINED */
         {pxmsg.i &MSGNUM=8163 &ERRORLEVEL=3}
         next-prompt sod_custpart.
         undo, retry.
      end.
   end.  /* IF SOD_CUSTPART <> "" */

   if sod_conrep < "1" or sod_conrep > "4" then do:
      /* NETTING LOGIC MUST BE 1,2,3,OR 4 */
      {pxmsg.i &MSGNUM=8165 &ERRORLEVEL=3}
      next-prompt sod_conrep.
      undo, retry.
   end.

   if not ({gpcode.v sod_psd_pat sch_sd_pat}) then do:
      /* VALUE MUST BE IN GEN. CODES */
      {pxmsg.i &MSGNUM=716 &ERRORLEVEL=3}
      next-prompt sod_psd_pat.
      undo, retry.
   end.

   if not ({gpcode.v sod_ssd_pat sch_sd_pat}) then do:
      /* VALUE MUST BE IN GEN. CODES */
      {pxmsg.i &MSGNUM=716 &ERRORLEVEL=3}
      next-prompt sod_ssd_pat.
      undo, retry.
   end.

   if sod_pkg_code <> ""
      and not can-find(pt_mstr where pt_part = sod_pkg_code)
   then do:
      /* ITEM NO. DOES NOT EXIST */
      {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
      next-prompt sod_pkg_code.
      undo, retry.
   end.

   sod_sch_data = string(sod_psd_pat,"x(2)")
                + string(sod_psd_time,"x(2)")
                + string(sod_ssd_pat,"x(2)")
                + string(sod_ssd_time,"x(2)").

   hide frame sod2.

end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* DO WITH FRAME SOD2 */

/* ALTERNATE CONTAINERS FRAME */
if sod_alt_pkg then do:
   {rcsomtac.i}
end.

if using_line_charges then do:
   {gprunmo.i
      &program = ""rcsolcmt.p""
      &module = "ACL"
      &param = """(input recid(so_mstr),
                   input recid(sod_det))"""}
end.

/* DETAIL COMMENTS */

if sodcmmts then do:
   cmtindx = sod_cmtindx.
   global_ref = sod_part.
   {gprun.i ""gpcmmt01.p"" "(input ""sod_det"")"}
/*GUI*/ if global-beam-me-up then undo, leave.

   sod_cmtindx = cmtindx.

end.

/* UPDATE REMOTE SO DETAIL RECORD IF THERE IS ONE*/
{gprun.i ""rcrsdup.p"" "(input recid(sod_det))"}
/*GUI*/ if global-beam-me-up then undo, leave.


sod_sched_chgd = yes.
release sod_det.
release scx_ref.

PROCEDURE display_msg:
   define input parameter ip_msg_nbr as integer no-undo.
   define input parameter ip_error_level as integer no-undo.

    { pxmsg.i &MSGNUM=ip_msg_nbr &ERRORLEVEL=ip_error_level}

END PROCEDURE. /*DISPLAY_MSG*/

PROCEDURE validate_container:
   define input parameter ip_container like ptc_part no-undo.
   define output parameter op_chargeable like mfc_logical no-undo.
   define output parameter op_charge_type like cct_charge_type no-undo.
   define output parameter op_msg_nbr as integer no-undo.

   assign
      op_chargeable = false
      op_charge_type = ""
      op_msg_nbr = 4447.
   /* ITEM HAS NOT BEEN DEFINED AS A CONTAINER*/

   for first ptc_det fields(ptc_part ptc_charge ptc_charge_type)
         no-lock where
         ptc_part = ip_container:
      assign
         op_chargeable = ptc_charge
         op_msg_nbr = 0.
      if ptc_charge then op_charge_type = ptc_charge_type.
   end.

END PROCEDURE. /* VALIDATE_CONTAINER*/

PROCEDURE get_charge_type:
   define input parameter ip_container like ptc_part no-undo.
   define input parameter ip_shipto like so_ship no-undo.
   define input parameter ip_curr like so_curr no-undo.
   define input-output parameter io_charge_type like cct_charge_type.

   for first cclsc_mstr
      fields(cclsc_shipto cclsc_part cclsc_curr cclsc_charge_type)
      no-lock
      where cclsc_shipto = ip_shipto
        and cclsc_part = ip_container
        and cclsc_curr = ip_curr:
   end.
   if not available cclsc_mstr then
      for first cclsc_mstr
         fields(cclsc_shipto cclsc_part cclsc_curr cclsc_charge_type)
         no-lock
         where cclsc_shipto = ""
           and cclsc_part = ip_container
           and cclsc_curr = ip_curr:
   end.
   if available cclsc_mstr then
      io_charge_type = cclsc_charge_type.
END PROCEDURE. /*GET_CHARGE_TYPE*/

PROCEDURE validate_charge_type:
   define input parameter ip_container like ptc_part no-undo.
   define input parameter ip_container_type like mfc_logical no-undo.
   define output parameter op_msg_nbr as integer no-undo.

   op_msg_nbr = 4396. /* NOT A VALID CHARGE TYPE */

   for first cct_mstr
      fields(cct_charge_type cct_container_type)
      no-lock
      where cct_charge_type = ip_container
        and cct_container_type = ip_container_type:
      op_msg_nbr = 0.
   end.
END PROCEDURE. /*VALIDATE_CHARGE_TYPE*/
